<template>
  <div class="user">
    <!-- 1、合同查看 -->
    <el-button type="primary" @click="ViewPDF">查看合同</el-button>
    <ViewPDF ref="pdf"/>

    <!-- 2、导出表格 -->
    <div class="table">
      <div class="header">
        <h2>用户管理</h2>
        <el-button @click="exportTable">导出表格</el-button>
      </div>
      <el-table border :data="tableData" style="width: 100%">
        <el-table-column prop="date" label="日期" width="180"></el-table-column>
        <el-table-column prop="name" label="姓名" width="180"></el-table-column>
        <el-table-column prop="address" label="地址"></el-table-column>
    </el-table>
    </div>
  </div>
</template>

<script>
import ViewPDF from './ViewPDF.vue'
import { export2Excel } from '@/common/js/util'
export default {
  components:{
    ViewPDF
  },
  data(){
    return{
      tableData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄'
      }, {
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1516 弄'
      }],
      //表头
      columns:[
        {title: '日期', key: 'date'},
        {title: '姓名', key: 'name'},
        {title: '地址', key: 'address'}
      ],
    }
  },
  methods:{
    ViewPDF(){
      this.$refs.pdf.dialogVisible = true;
    },

    //导出
    exportTable(){
      // export2Excel('表头', '需要导出的数据')
      export2Excel(this.columns, this.tableData, '用户列表')
    }
  }
}
</script>

<style lang="less" scoped>
  .user{
    button{
      margin: 20px 0 0 10px;
    }
    .table{
      padding: 20px;
      .header{
        content: '';
        display: block;
        clear: both;
        h2{
          font-size: 18px;
          font-weight: 600;
          text-align: center;
        }
        button{
          float: right;
          right: 20px;
          margin: -10px 0 10px;
        }
      }
      
    }
  }
  
</style>